package com.liangzhong.model.bag
{
	import com.liangzhong.errortip.ErrorTips;
	import com.liangzhong.model.AppData;
	
	import flash.utils.ByteArray;
	
	import lz.controls.Alert;

	/**
	 *背包服务器数据返回解析 
	 * @author lake
	 * 
	 */	
	public class BagServerDataParse
	{
		/**
		 * 读取升级返回数据
		 * @param data
		 * 
		 */		
		public static function readGradeUp(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.level		= data.readByte();//当前等级
				resObj.coin			= data.readUnsignedInt();//下级所需欧元
				resObj.cell			= data.readShort();//下级所增格子数
				resObj.defaultcell	= data.readShort();//默认格子数
				resObj.casecell		= data.readShort();//点券已开格子数
				AppData.getInstance().bagDataManager.bagInfo.level = resObj.level;
				AppData.getInstance().bagDataManager.bagInfo.coin = resObj.coin;
				AppData.getInstance().bagDataManager.bagInfo.nextcell = resObj.cell;
				AppData.getInstance().bagDataManager.bagInfo.defaultCellNum = resObj.defaultcell;
				AppData.getInstance().bagDataManager.bagInfo.cashCellNum = resObj.casecell;
				var curtime :Number = AppData.getInstance().time;
				AppData.getInstance().bagDataManager.bagInfo.pretime = curtime;
				Alert.showErrorTip("升级成功");
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 *读取开格子返回数据 
		 * @param data
		 * 
		 */		
		public static function readOpenCells(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.defaultcell	= data.readShort();//默认格子数
				resObj.casecell		= data.readShort();//点券已开格子数
				AppData.getInstance().bagDataManager.bagInfo.defaultCellNum = resObj.defaultcell;
				AppData.getInstance().bagDataManager.bagInfo.cashCellNum = resObj.casecell;
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
	}
}